#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstring>
#include <unistd.h>
#define NUM 10
int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        std::cout << "格式错误" << std::endl;
        exit(1);
    }
    int sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock < 0)
    {
        std::cout << "socket enrro" << std::endl;
        exit(2);
    }
    sockaddr_in serve;
    memset(&serve, 0, sizeof(serve));
    serve.sin_addr.s_addr = inet_addr(argv[1]);
    serve.sin_family = AF_INET;
    serve.sin_port = htons(atoi(argv[2]));
    int ret = connect(sock, (sockaddr *)&serve, sizeof(serve));
    // std::cout<<ret<<std::endl;
    if (ret >= 0)
    {
        // 连接成功
        std::string buffer;
        getline(std::cin, buffer);
        // std::cout<<buffer<<std::endl;
        send(sock, buffer.c_str(), buffer.size(), 0);
        char bufe[NUM];
        memset(bufe, 0, NUM);
        ssize_t s = recv(sock, bufe, NUM, 0);
        std::cout << bufe << std::endl;
        close(sock);
    }
    else
    {
        std::cout<<"连接错误"<<std::endl;
        exit(5);
    }
    return 0;
}